function  masterfile_gpu(file,seconds)
if nargin < 2, seconds = 0; end
file = 'technobeat.wav';
if seconds == 0
    [y, Fs] = wavread(file);      % data= y, sampling freq = Fs
else
    [y, Fs] = wavread(file,[1 44100*seconds]);      % data= y, sampling freq = Fs
end


beatdetectionon = true;
%[y Fs] = mp3read('ITHIAH.mp3', [44100*0 44100*25],1); %mono
%[y, Fs] = wavread(file, [1 44100*30]);      % y is sound data, Fs is sample frequency.
%[y, Fs] = wavread(file);      % y is sound data, Fs is sample frequency.

player = audioplayer(y,Fs);
gclf;
y = y(:,1)*2;

y = y*5;
y = gsingle(y);
lenY = length(y);

wavbeat = zeros(lenY,6);

t = (1:lenY)/Fs;         % time
gfigure;
%set(h, 'Color', [.1,.1,.05]); %nackground color

timeToJump = 2.2;
timeSkip = 1000/44100;

myt = tic;

a= size(y);
lengthSong = a(1)/Fs;

g1max=1;
g2max=1;
g3max=1;



[xs,ys,zs] = sphere(10);


%%%%%%

history =[]; %the buffer to keep for the past.
lastChanged = 1;
numToRemember = 4;
lastGoodTime = 0;

play(player);
numSeconds = 0;
goodTill = 0;
val = [];
while numSeconds<lengthSong
    tic;
    numSeconds = toc(myt);
    
    indnew = [ceil((numSeconds-timeSkip)*44100) ceil((numSeconds+timeSkip)*44100)];
    
    if (indnew(1) <= 0)
        indnew(1) = 1;
    end
    if (indnew(2) >= lenY)
        indnew(2)= lenY;
    end
    ind = [indnew(1):indnew(end)];
    if length(ind) == 0
        break;
    end
    startFrame = ceil(numSeconds*44100);
    endFrame = ceil((numSeconds+2.2)*44100);
    
    if beatdetectionon
        if (or((goodTill <= numSeconds),(goodTill-numSeconds) < .5)) %testing if we're past the last analyzed point, or close to it, .5s
            if (lengthSong - numSeconds > timeToJump)
                output = rhythm_gpu(y(startFrame:endFrame));
                goodTill = numSeconds + timeToJump;
                lastGoodTime = numSeconds;
            else
                output = rhythm_gpu(y((ceil((lengthSong - timeToJump)*44100):ceil((lengthSong)*44100))));
                goodTill = lenY;
                lastGoodTime = numSeconds;
                
            end
            
            gsubplot(2,2,2);
            
            upperlimit = gones(1, 1)*1;
            
            plot(upperlimit);
            ghold_on;
            plot(upperlimit*0); %lower limit
            
            for i=1:6
                saveForLater = output;
                c =abs(output(:,i));
                c = c/max(c);
                plot(c);
                
                [peak loc] = max(c);
                
                if (startFrame+loc) < lenY
                    wavbeat(startFrame + loc,i) = 1;
                end
                
                
            end
            ghold_off
            
        end
        
    end
    
    
    gsubplot(2,2,1);
    if g1max < max(y(ind))
        g1max = max(y(ind));
    end
    
    upperlimit = gones(ind(end)-ind(1), 1)*g1max;
    plot(upperlimit);
    ghold_on
    plot(upperlimit*-1); %lower limit
    
    plot(y(ind)) %plotting the data
    
    
    [a b] = size(history);
    
    for i=1:b
        plot(history(:,i));
        
    end
    ghold_off
    
    [c d] = size(y(ind));
    if c == 2001
        [a b] = size(history);
        if b<numToRemember
            history = horzcat(history, y(ind));
        else
            history(:,lastChanged) = y(ind);
            lastChanged=lastChanged+1;
            if lastChanged == numToRemember+1
                lastChanged = 1;
            end
            
        end %end if statement
        
    end %end making surte we're adding the same length
    
    
    %%%
    if beatdetectionon==true
        gsubplot(2,2,3);
         deltatime = numSeconds-lastGoodTime;
         deltaFrame = ceil(deltatime*44100)
        if deltaFrame == 0
           deltaFrame = 1; 
        end

        %maxvalues = gzeros(1,6);
        
        X = gsingle([xs(:)*saveForLater(deltaFrame,1)]); %middle
        Y = gsingle([ys(:)*saveForLater(deltaFrame,1)]);
        Z = gsingle([zs(:)*saveForLater(deltaFrame,1)]);
        
        
        
        X = [X; xs(:)*saveForLater(deltaFrame,2)-10]; %bottom left
        Y = [Y; ys(:)*saveForLater(deltaFrame,2)-10];
        Z = [Z; zs(:)*saveForLater(deltaFrame,2)];
        
        X = [X; xs(:)*saveForLater(deltaFrame,3)]; %top right
        Y = [Y; ys(:)*saveForLater(deltaFrame,3)];
        Z = [Z; zs(:)*saveForLater(deltaFrame,3)-10];
        
        X = [X; xs(:)*saveForLater(deltaFrame,4)-10]; %top left
        Y = [Y; ys(:)*saveForLater(deltaFrame,4)];
        Z = [Z; zs(:)*saveForLater(deltaFrame,4)];
        
        X = [X; xs(:)*saveForLater(deltaFrame,5)-10]; %top
        Y = [Y; ys(:)*saveForLater(deltaFrame,5)+5];
        Z = [Z; zs(:)*saveForLater(deltaFrame,5)-10];
        
        
        
        X = [X; xs(:)*saveForLater(deltaFrame,6)]; %bottom right
        Y = [Y; ys(:)*saveForLater(deltaFrame,6)-10];
        Z = [Z; zs(:)*saveForLater(deltaFrame,6)-10];
        
        limits = 13;
        X = [X;-1*limits;1*limits]; %limits
        Y = [Y;-1*limits;1*limits];
        Z = [Z;-1*limits;1*limits];
        scatter3(X(:),Y(:),Z(:))
        %%%
    end
    
    endSeconds = toc(myt) -numSeconds;
    pause(.01);
    
    val = [val toc];
    
end
mean(val)